package board.spring.mvc.board.dao;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Calendar;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import board.spring.mvc.board.interfaces.ArticleDao;
import board.spring.mvc.board.dao.mapper.ArticleMapper;
import board.spring.mvc.board.model.Article;

@Repository
public class ArticleDaoImpl implements ArticleDao {

	@Autowired ArticleMapper articleMapper;
	
	public Article selectArticle(int num) {
		return articleMapper.selectArticle(num);
	}
	
	public List<Article> selectArticles() {
		return articleMapper.selectArticles();
	}
	
	public void insertArticle(Article article) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		article.setRegdate(sdf.format(cal.getTime()));
		articleMapper.insertArticle(article);
	}
	
	public void deleteArticle(int num) {
		articleMapper.deleteArticle(num);
	}
}
